


var randomTags = new Vue({
    el: '#random_tags',
    data: {
        tags: ['asd', 'ndsifh', 'java', 'js', 'php','python', 'c++', '#c', 'css', 'html', 'asd', 'ndsifh', 'java', 'jsfdsfdgdfg', 'php','python', 'c++', '#c', 'css', 'html'],
        id:''
    },
    computed:{
        randomColor: function () {
            return function () {
                const red = Math.random() * 255;
                const green = Math.random() * 255;
                const blue = Math.random() * 255;
                return "rgb(" + red + ", " + green + ", " + blue + ")"
            }
        },
        randomSize: function () {
            return function () {
                const size = (Math.random() * 20 + 12) + 'px';
                return size;
            }
        }
    },
    created:function(){
        axios({
            method: "get",
            url: "/queryAllTag"
        }).then((res) => {
            console.log(res.data.data)
            var tagList = []
            var temp = res.data.data
            for(var i = 0; i < temp.length; i ++){
                tagList.push({text:temp[i].tag, link:"/?tag=" + temp[i].tag})
            }
            randomTags.tags = tagList;
            randomTags.tags.sort(() => {
                return Math.random() > 0.5 ? 1 : -1
            })
        }).then( axios({
            method: "get",
            url: "/queryBlogIdByTagId"
        }).then((res) => {

        }))
       
    }
})



var newHot = new Vue({
    el: "#new_hot",
    data: {
        titleList: [
            {title: "这是一个链接哈", link:'https://www.baidu.com'},
        ]
    },
    computed:{

    },
    created:function () {
        axios({
            method: "get",
            url: "/queryHotBlog"
        }).then((res) => {
            var list = [];
            for(var i = 0; i < res.data.data.length; i ++) {
                var hotObj = {}
                hotObj.title = res.data.data[i].title;
                hotObj.link = "/blog_detail.html?bid=" + res.data.data[i].id;
                list.push(hotObj);
            }
            newHot.titleList = list;
        })
    }
})

var newComments = new Vue({
    el: '#new_comments',
    data: {
        commentList: [
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
            {username: '张氏', date: '2020-5-20', content:'520依旧在敲代码，这是真爱吗'},
        ]
    },
    computed:{

    },
    created:function () {
        axios({
            method: "get",
            url: "/queryNewComment"
        }).then((res) => {
            console.log(res.data.data);
            var result = [];
            for(var i = 0; i < res.data.data.length; i++) {
                var comList = {};
                comList.username = res.data.data[i].user_name;
                comList.date = res.data.data[i].ctime;
                comList.content = res.data.data[i].comments
                result.push(comList);
            }
            newComments.commentList = result;
        })
    }
})